package com.tj.jinzao.provider;

import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.provider.BaseColumns;

import com.tj.jinzao.BuildConfig;

/**
 * 数据库表
 * created by wjy 2015/11/2
 */
public final class ProviderContract {
    // The authority for the provider
    public static final String AUTHORITY = BuildConfig.APPLICATION_ID;
    // A content:// style uri to the authority for the provider
    public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY);

    private static final String TYPE_PREFIX = "vnd.android.cursor.dir/com.zk.asap.provider.";
    private static final String ITEM_TYPE_PREFIX = "vnd.android.cursor.item/com.zk.asap.provider.";

    public static final String UPDATE_ON_INSERT_FAILURE = "update_on_insert_failure";
    public static final String UPDATE_ON_INSERT_FAILURE_KEY = "update_on_insert_failure_key";

    public static final String FIRST_PAGE = "first_page";


    /**
     * 用户表
     */
    public static final class User implements BaseColumns {

        public static final String TABLE_NAME = "user";
        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, TABLE_NAME);
        public static final String CONTENT_TYPE = TYPE_PREFIX + TABLE_NAME;
        public static final String CONTENT_ITEM_TYPE = ITEM_TYPE_PREFIX + TABLE_NAME;

        public static final String USER_ID = "user_id"; //用户id
        public static final String DATA = "data";//数据

        public static final void createOriginTable(SQLiteDatabase db) {
            db.execSQL("CREATE TABLE if NOT EXISTS " + TABLE_NAME + " ("
                    + _ID + " INTEGER PRIMARY KEY, "
                    + USER_ID + " TEXT, "
                    + DATA + " TEXT "
                    + ")");
            try {
                db.execSQL("CREATE UNIQUE INDEX User_id ON "
                        + TABLE_NAME + " (" + USER_ID + ")");
            } catch (Exception e) {
            }
        }
    }

    /**
     * 用户表
     */
    public static final class City implements BaseColumns {
        public static final String TABLE_NAME = "city";
        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, TABLE_NAME);
        public static final String CONTENT_TYPE = TYPE_PREFIX + TABLE_NAME;
        public static final String CONTENT_ITEM_TYPE = ITEM_TYPE_PREFIX + TABLE_NAME;

        public static final String CITY_CODE = "city_code"; //用户id
        public static final String CITY_NAME = "city_name"; //头像
        public static final String PINYIN = "pinyin";//token
        public static final String FATHER_NAME = "father_name";//昵称

        public static final void createOriginTable(SQLiteDatabase db) {
            db.execSQL("CREATE TABLE if NOT EXISTS " + TABLE_NAME + " ("
                    + _ID + " INTEGER PRIMARY KEY, "
                    + CITY_CODE + " TEXT, "
                    + CITY_NAME + " TEXT, "
                    + PINYIN + " TEXT, "
                    + FATHER_NAME + " TEXT "
                    + ")");
        }
    }
}
